<?php
class PageController extends CommonController{
	public function update(){
		if($this->isGet()){
			$info=M('Page')->where(array('key'=>$_GET['key']))->find();
			if(empty($info)){
				$page=array();
				$page['key']=$_GET['key'];
				$id=M('Page')->save($page);
				$info['id']=$id;
			}
			$this->assign('info',$info);
			$this->display();
		}else{
			$db = D ( $this->table );
			$db->create () or $this->error ( $db->getError () );
			if ($db->update ( $_POST )) {
				$this->redirect ();
			} else {
				$this->error ($db->getError()?$db->getError():'编辑失败' );
			}
		}
	}
}